home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / virt.c < prev    next >
C/C++ Source or Header  |  1993-06-18  |  4KB  |  163 lines

  1. /*
  2. *                virt.c
  3. *
  4. * Virtual room handler for Citadel-86.
  5. */
  6. #include "ctdl.h"
  7. /*
  8. *                history
  9. *
  10. * 91Nov15 HAW Restructured.
  11. * 88Apr01 HAW Final cleanup before release.
  12. */
  13. /*
  14. *                contents
  15. *
  16. *    VirtInit()        Initialize the virtual room stuff
  17. *    InitVNode()        Init for a new node
  18. *    UpdVirtStuff()        Updates the virtual stuff
  19. *    VirtSummary()        Does real work of updating virtual stuff
  20. *
  21. */
  22. VirtualRoom *VRoomTab;
  23. VirtNet     *VirtNetList;
  24. char VirtualInUse = FALSE;
  25. int  VirtSize, VNetSize;
  26. extern NetBuffer netBuf;
  27. extern CONFIG    cfg;
  28. extern int       thisNet;
  29. extern FILE      *netLog;
  30. extern char      netDebug, TrError;
  31. /*
  32. * VirtInit()
  33. *
  34. * This function initializes the virtual room stuff, if available.  The virtual
  35. * room stuff is created by the virtadmn utility, so this is a non-fatal,
  36. * non-warning failure -- the sysop doesn't even know that this stuff ain't
  37. * here.
  38. */
  39. void VirtInit()
  40.   {
  41.   #ifndef NO_VIRTUAL_ROOMS
  42.   FILE *fd;
  43.   SYS_FILE fn;
  44.   long size;
  45.   extern char *R_W_ANY;
  46.   makeVASysName(fn, "ctdlvrm.sys");
  47.   if ((fd = safeopen(fn, R_W_ANY)) == NULL)
  48.   return;    /* Depend on initializer to handle VirtualInUse */
  49.   totalBytes(&size, fd);
  50.   VRoomTab = (VirtualRoom *) GetDynamic((int) size);
  51.   fread((char *) VRoomTab, (int) size, 1, fd);
  52.   fclose(fd);
  53.   VirtSize = (int) size / sizeof *VRoomTab;
  54.   VirtualInUse = TRUE;
  55.   makeVASysName(fn, "ctdlvnet.sys");
  56.   if ((fd = safeopen(fn, R_W_ANY)) == NULL)
  57.   crashout("ctdlvnet.sys is missing!!");
  58.   totalBytes(&size, fd);
  59.   VirtNetList = (VirtNet *) GetDynamic((int) size);
  60.   VNetSize = size / sizeof *VirtNetList;
  61.   fread(VirtNetList, (int) size, 1, fd);
  62.   fclose(fd);
  63.   #endif
  64.   
  65.   }
  66. /*
  67. * InitVNode()
  68. *
  69. * When a new node is added to the net list, this function initializes the
  70. * virtual part of the new node.  This consists of enlarging the vnet table
  71. * size if necessary, and initializing the room pointers to -1, indicating
  72. * that none of them are in use.  Finally, the virtual tables on disk are
  73. * updated.
  74. */
  75. void InitVNode(int slot)
  76.   {
  77.   #ifndef NO_VIRTUAL_ROOMS
  78.   int rover;
  79.   if (!VirtualInUse) return ;
  80.   if (slot >= VNetSize) 
  81.     {
  82.     VirtNetList = realloc(VirtNetList, (slot+1) * sizeof *VirtNetList);
  83.     VNetSize = slot + 1;
  84.     
  85.     }
  86.   for (rover = 0; rover < VIRT_LIMIT; rover++)
  87.   VirtNetList[slot].VirtList[rover].WhichVirt = -1;
  88.   UpdVirtStuff();
  89.   #endif
  90.   
  91.   }
  92. /*
  93. * UpdVirtStuff()
  94. *
  95. * This function updates the virtual data on disk.
  96. */
  97. void UpdVirtStuff()
  98.   {
  99.   #ifndef NO_VIRTUAL_ROOMS
  100.   FILE *fd;
  101.   SYS_FILE fn;
  102.   extern char *R_W_ANY;
  103.   if (!VirtualInUse) return ;
  104.   VirtSummary();
  105.   makeVASysName(fn, "ctdlvrm.sys");
  106.   if ((fd = safeopen(fn, R_W_ANY)) == NULL)
  107.   crashout("ctdlvrm.sys is missing!");
  108.   fwrite(VRoomTab, VirtSize, sizeof *VRoomTab, fd);
  109.   fclose(fd);
  110.   makeVASysName(fn, "ctdlvnet.sys");
  111.   if ((fd = safeopen(fn, R_W_ANY)) == NULL)
  112.   crashout("ctdlvnet.sys is missing!!");
  113.   fwrite(VirtNetList, cfg.netSize, sizeof *VirtNetList,  fd);
  114.   fclose(fd);
  115.   #endif
  116.   
  117.   }
  118. /*
  119. * VirtSummary()
  120. *
  121. * This function handles post-call cleanup.
  122. */
  123. void VirtSummary()
  124.   {
  125.   #ifndef NO_VIRTUAL_ROOMS
  126.   int rover, another;
  127.   for (rover = 0; rover < VirtSize; rover++) 
  128.     {
  129.     if (VRoomTab[rover].vrChanged & LD_CHANGE) 
  130.       {
  131.       VRoomTab[rover].vrHiLD++;
  132.       for (another = 0; another < VIRT_LIMIT; another++)
  133.       if (VirtNetList[thisNet].VirtList[another].WhichVirt == rover) 
  134.         {
  135.         VirtNetList[thisNet].VirtList[another].LDSent =
  136.         VRoomTab[rover].vrHiLD;
  137.         break;
  138.         
  139.         }
  140.       /*if (another == VIRT_LIMIT) splitF(netLog, "Unexpected mistake 1 in LDVirtSummary!\n"); */
  141.       
  142.       }
  143.     if (VRoomTab[rover].vrChanged & LOC_CHANGE) 
  144.       {
  145.       VRoomTab[rover].vrHiLocal++;
  146.       for (another = 0; another < VIRT_LIMIT; another++)
  147.       if (VirtNetList[thisNet].VirtList[another].WhichVirt == rover) 
  148.         {
  149.         VirtNetList[thisNet].VirtList[another].LocSent =
  150.         VRoomTab[rover].vrHiLocal;
  151.         break;
  152.         
  153.         }
  154.       /*if (another == VIRT_LIMIT) splitF(netLog, "Unexpected mistake 2 in LocVirtSummary!\n"); */
  155.       
  156.       }
  157.     VRoomTab[rover].vrChanged = 0;
  158.     
  159.     }
  160.   #endif
  161.   
  162.   }
  163.